package MtG.publicClass;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Random;

/**
 * Deck.java is an abstract class that is a template for creating premade card decks.
 * @author Marek Sirp
 * @author Jaan Sepp
 */
public abstract class Deck implements Serializable{
	/**
	 * Determines if a de-serialized file is compatible with this class.
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * ArrayList for holding all the cards in this deck.
	 */
	private ArrayList<Card> cardsInDeck = new ArrayList<Card>();
	
	/**
	 * @return random card from this deck.
	 */
	public Card takeRandomCard(){
		int i = cardsInDeck.size();
		Random r = new Random();
		int index = Math.abs(r.nextInt()) % i;
		Card temp = cardsInDeck.get(index);
		cardsInDeck.remove(index);
		return temp;
	}

	/**
	 * @param currentCard the reference to the card that will be added to this deck.
	 */
	public void addCardToDeck(Card currentCard){
		this.cardsInDeck.add(currentCard);
	}
	
	/**
	 * @param index integer that shows the index of the card to be removed from this deck.
	 */
	public void removeCardFromDeck(int index){
		cardsInDeck.remove(index);
	}
	
	/**
	 * @return ArrayList with all the cards in this deck.
	 */
	public ArrayList<Card> getDeck(){
		return this.cardsInDeck;
	}

}
